﻿using S7.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace S7NetPlus_Project
{
    internal class Program
    {
        static void Main(string[] args)
        {
         
        }

        static void S7NetPlusTest()
        {
            Plc plc = new Plc(CpuType.S71500, "192.168.128.3", 0, 2);

            if (!plc.IsConnected)
            {
                plc.Open();
            }

            object val1 = plc.Read("I0.0");

            object val2 = plc.Read("DB1.DBW72");

            plc.Write("DB1.DBW72", (ushort)120);

            object val3 = plc.Read("DB1.DBW72");

            object dwords = plc.Read(DataType.DataBlock, 1, 0, VarType.Real, 9);

            Console.WriteLine("执行结束");
            /*
            // 从1号数据库的0号地址开始，读取200个字节
            byte[] dataBuff1 = plc.ReadBytes(DataType.DataBlock, 1, 0, 200);
            byte[] writeData = new byte[] { 0, 1, 2, 3 };
            plc.WriteBytes(DataType.DataBlock, 1,0,writeData);

            // 读取和解码
            object dwords = plc.Read(DataType.DataBlock, 1, 0, VarType.DWord, 20);
            plc.Write(DataType.DataBlock, 1, 0, 10);

            // 读取 S7 Word
            ushort result = (ushort)plc.Read("DB1.DBW0");

            // 写入 S7 Word 
            ushort val = 40000;
            plc.Write("DB1.DBW0", val);

            // 读取 S7 DWord
            uint result2 = (uint)plc.Read("DB1.DBD20");

            // 写入 S7 DWord
            uint val2 = 1000;
            plc.Write("DB1.DBD40", val2);
            */


            plc.Close();
        }
    }
}
